<?php

namespace App\Model\Es;

use EasySwoole\Component\Di;

class EsBase
{

    public $esClient = null;

    public function __construct()
    {
        $this->esClient = Di::getInstance()->get('ES');
    }

    public function searchName($name, $type = 'match',$from = 0,$size = 10)
    {
        $name = trim($name);
        if(empty($name)){
            return [];
        }
        $params = [
            'index' => $this->index,
            'body' => [
                'query' => [
                    $type => [
                        'name' => $name,
                    ]
                ],
                'from' => $from,
                'size' => $size,
            ],
        ];
        $client = Di::getInstance()->get('ES');
        $result = $client->search($params);
        return $result;
    }

}